import streamlit as st
from NPC import NPC
from dotenv import load_dotenv

st.sidebar.title("基础信息")
nickname = st.sidebar.text_input("昵称", value="大头天尊")
gender = st.sidebar.radio("性别", ("男", "女"), index=0)
age = st.sidebar.number_input("年龄", min_value=18, max_value=100, value=20)
Faction = st.sidebar.selectbox("门派", ("武当", "峨眉", "少林", "天山"), index=0)
level = st.sidebar.selectbox("武学造诣", ("初学乍练", "略有小成", "炉火纯青", "登峰造极", "一代宗师"), index=4)
self_description = st.sidebar.text_area("自我描述", value="武功盖世")
personality_traits = st.sidebar.multiselect("性格特点", ["乐观", "耐心", "诚实", "自律"], default=["乐观", "耐心"])
npc = NPC(nickname, gender, age, Faction, level, self_description, personality_traits)

def main():
    global npc
    load_dotenv()
    st.title('关卡信息')
    # 关卡名称下拉列表
    level_name = st.selectbox(
        '请选择一个关卡:',
        (
            "第一关：大闹青城山",
            "第二关：幽暗水底洞",
            "第三关：荒漠金字塔",
            "第四关：云端之城",
            "第五关：末日火山"
        )
    )

    st.write('关卡描述：')
    # 根据关卡名称获得描述并显示
    game_level = npc.get_level_description(level_name)
    st.write(game_level)
    st.title('规则信息')  
    # 创建一个多行文本框并且填入规则列表
    rules_input = st.text_area("以下是确保游戏中虚拟角色遵守的规则列表：", 
                 value=npc.get_rules_text(), 
                 height=300)

    st.title("测试功能")
    user_input = st.text_input("与虚拟角色对话", key="user_input")
    if st.button('发送'):
        st.write("用户:", user_input)
        response = npc.queryLLM(game_level,rules_input,user_input)
        st.write("虚拟角色:", response)
    else:
        st.write("请先生成一个虚拟角色。")
if __name__ == "__main__":
    main()
